<?php

namespace App\Http\Resources\Article;

use App\Http\Resources\BaseResource;
use App\Models\Article\ArticleModel;
use App\Models\Article\ArticleRecommendModel;

class ArticleRecommendListResource extends BaseResource
{
    public function toArray($request): array
    {
        return [
            "id"                => $this->id,
            "title"             => $this->title,
            "cover"             => $this->cover,
            "status"            => $this->status,
            "statusText"        => $this->statusText,
            'description'       => $this->description,
            "articleId"         => $this->articleId,
            "contentType"       => $this->contentType,
            "contentTypeText"   => translateEnumCodeToCn(
                ArticleRecommendModel::CONTENT_TYPE_TEXT,
                $this->contentType,
                "-"
            ),
            "effectiveType"     => $this->effectiveType,
            "effectiveTypeText" => translateEnumCodeToCn(
                ArticleRecommendModel::EFFECTIVE_TYPE_TEXT,
                $this->effectiveType,
                "-"
            ),
            "startAt"           => $this->effectiveType == ArticleRecommendModel::EFFECTIVE_TYPE_LIMIT ? date('Y-m-d H:i:s',
                $this->startAt) : 0,
            "endAt"             => $this->effectiveType == ArticleRecommendModel::EFFECTIVE_TYPE_LIMIT ? date('Y-m-d H:i:s',
                $this->endAt) : 0,
            "type"              => $this->type,
            'typeText'          => ArticleRecommendModel::TYPE_TEXT[$this->type],
            'sort'              => $this->sort,
            'isActivate'        => $this->isActivate,
            'isActivateText'    => ArticleRecommendModel::ACTIVATE_TEXT[$this->isActivate],
            "createdAt"         => date('Y-m-d H:i:s', $this->createdAt->timestamp),
            "updatedAt"         => date('Y-m-d H:i:s', $this->updatedAt->timestamp),
            'redirectUrl'       => $this->redirectUrl,
        ];
    }
}
